<template>
    <view class="page" :style="'background: url(' + getCloudImg('common2/consume-bg.png') + ') no-repeat; background-size: 100% 100%;'">
        <uni-nav-bar :fixed="true" backgroundColor="rgba(255,255,255,0)" :color="style.primary" :border="false" status-bar left-icon="left" title="票码核销" @clickLeft="routerBack" />
        <view class="content">
            <view class="custom-input-wrap">
                <input v-model="form.subcodeCode" type="text" :inputBorder="false" :maxlength="100" placeholder="请输入核销码" class="custom-input" />
            </view>
            <view class="custom-button" @click="submit">确认</view>
        </view>
    </view>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { toast, routerPush, isEmpty, getCloudImg, routerBack } from '@/assets/js/utils'
import style from '../../assets/css/variables.module.scss'

import { getDetailByConsumeCode } from '@/service/consume'

onLoad(() => {})

const form = ref({
    subcodeCode: ''
})

const submit = async () => {
    if (isEmpty(form.value.subcodeCode)) {
        toast('请输入核销码')
        return
    }
    uni.showLoading({
        mask: true
    })
    let [result, err] = await getDetailByConsumeCode(form.value)
    uni.hideLoading()
    if (result) {
        if (result.detail) {
            routerPush(`/pages/consume/detail?code=${form.value.subcodeCode}`)
        } else {
            toast(result.resultNote)
        }
    }
}
</script>

<style lang="scss">
.page {
    min-height: 100vh;
}

.content {
    padding: 170rpx 88rpx 0 88rpx;

    .custom-input-wrap {
        position: relative;
        margin-bottom: 80rpx;

        .custom-input {
            width: calc(574rpx - 32rpx * 2);
            height: 112rpx;
            background: #ffffff;
            border-radius: 12rpx;
            border: 1rpx solid #2e5f93;
            font-size: 32rpx;
            color: $primary;
            padding: 0 32rpx;
        }
    }
}
</style>
